﻿using CarRental.DataAccessLayer;
using CarRental.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CarRental.View {
    public partial class AddCar : System.Web.UI.Page {
        List<car> _lst = new List<car>();
        Wcf _wcf = new Wcf();

        protected void Page_Load(object sender, EventArgs e) {
            if (!IsPostBack) {            
            ddlDepot.DataSource = new CarRental.Helpers.OptionItems.DepotLst();
            ddlDepot.DataValueField = "Key";
            ddlDepot.DataTextField = "Title";
            ddlDepot.DataBind();

            ddlDrivetrains.DataSource = new CarRental.Helpers.OptionItems.DriveTrainsLst();
            ddlDrivetrains.DataValueField = "Key";
            ddlDrivetrains.DataTextField = "Title";
            ddlDrivetrains.DataBind();

            ddlColor.DataSource = new CarRental.Helpers.OptionItems.ColorLst();
            ddlColor.DataValueField = "Key";
            ddlColor.DataTextField = "Title";
            ddlColor.DataBind();

            ddlCarType.DataSource = new CarRental.Helpers.OptionItems.CarTypeLst();
            ddlCarType.DataValueField = "Key";
            ddlCarType.DataTextField = "Title";
            ddlCarType.DataBind();

            ddlShop.DataSource = new CarRental.Helpers.OptionItems.ShopLst();
            ddlShop.DataValueField = "Key";
            ddlShop.DataTextField = "Title";
            ddlShop.DataBind();

            _lst = _wcf.GetCar().ToList<car>();
            }
        }

        protected void btnAddCar_Click(object sender, EventArgs e) {
            car _car = new car();
            _car.car_no = tbCarNo.Text;
            _car.car_typecode = ddlCarType.SelectedValue;
            _car.car_model = tbCarModel.Text;
            _car.depot = "";
            _car.drivetrains = "";
            _car.color = ddlColor.SelectedValue;
            _car.tonnage = decimal.Parse(tbTonnage.Text);
            _car.status = "A";
            _car.buy_in_date = cldBuyInDate.SelectedDate;
            _car.buy_in_cost = decimal.Parse(tbBuyinCost.Text);
            _car.rent_price = decimal.Parse(tbRentPrice.Text);
            _car.last_rental_date = DateTime.MinValue;
            _car.last_rental_order_no = "";
            _car.license_no = tbLicense.Text;
            _car.number_of_rental = 0;
            _car.shopcode = ddlShop.SelectedValue;

            _wcf.InsertCar(_car);

        }

    }
}